package org.example.utils;

import cn.hutool.json.JSONObject;
import cn.hutool.jwt.JWT;
import cn.hutool.jwt.signers.JWTSignerUtil;

import java.util.Collection;
import java.util.Map;

/**
 * @BelongsProject：blockchain-APTrace
 * @CreateTime 2024-05-27-16:32
 * @Author SweetPig
 */
public class JwtUtils {

    public static String create(Map<String, Object> map) {
        JWT jwt = JWT.create();
        map.forEach((k, v) -> {
            jwt.setPayload(k, v.toString());
        });
        return jwt.setSigner(JWTSignerUtil.none()).sign();
    }

    public static String create(String Id) {
        JWT jwt = JWT.create().setPayload("id", Id);
        return jwt.setSigner(JWTSignerUtil.none()).sign();
    }

    public static JSONObject of(String token) {
        return JWT.of(token).getPayloads();
    }

}
